package com.flexcloudsdk.xmpp;

import java.util.logging.Logger;

import com.flexcloudsdk.xmpp.CloudSubscription;
import com.google.appengine.api.xmpp.SubscriptionBuilder;
import com.google.appengine.api.xmpp.SubscriptionType;
import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Subscription;


public class CloudSubscriptionBuilder {
		private static final Logger log = Logger.getLogger(CloudSubscriptionBuilder.class.getName());
		private SubscriptionBuilder builder;
		
		public CloudSubscriptionBuilder() {
			log.info("CloudSubscriptionBuilder has been created by BlazeDS");
			builder = new SubscriptionBuilder();
		}
		
		public CloudSubscription build() {
			Subscription value  = null;
			if (builder != null)
				value =  builder.build();
			else
				log.severe("build call failed in CloudScubscription due to SubScriptionBuilder being null");
			CloudSubscription subscription = new CloudSubscription();
			 subscription.setSubScription(value);
			 return subscription;
		}
		
		public CloudSubscriptionBuilder withFromJid(JID fromJid) {
			if (builder != null)
				builder =  builder.withFromJid(fromJid);
			else
				log.severe("withFromJid call failed in CloudScubscription due to SubScriptionBuilder being null");
			return this;
		}
		
		public CloudSubscriptionBuilder withStanza(String stanza) {
			if (builder != null)
				builder.withStanza(stanza);
			else
				log.severe("withStanza call failed in CloudScubscription due to SubScriptionBuilder being null");
			return this;
		}
		
		public CloudSubscriptionBuilder withSubscriptionType(SubscriptionType subscriptionType) {
			if (builder != null)
				builder.withSubscriptionType(subscriptionType);
			else
				log.severe("withSubscriptionType call failed in CloudScubscription due to SubScriptionBuilder being null");
			return this;
		}
		
}
